import com.weaverboot.tools.baseTools.BaseTools;
import com.weaverboot.tools.enumTools.weaComponent.WeaBooleanEnum;
import com.weaverboot.weaComponent.impl.weaTable.column.impl.DefaultWeaTableColumn;
import com.weaverboot.weaComponent.impl.weaTable.column.inte.AbstractWeaTableColumn;
import com.weaverboot.weaComponent.impl.weaTable.table.impl.DefaultWeaTable;
import com.weaverboot.weaComponent.impl.weaTable.table.inte.AbstractWeaTable;
import com.weaverboot.weaResultMsg.impl.formResult.impl.WeaFormSendComponentResultMsg;
import com.weaverboot.weaResultMsg.impl.tableResult.impl.DefaultWeaTableComponentSendResultMsg;
import com.weaverboot.weaResultMsg.impl.tableResult.inte.AbstractWeaTableComponentSendResultMsg;

public class Test1 {
    public AbstractWeaTableComponentSendResultMsg getTable(DemoTable demoTable) {
        //创建 table 发送消息体
        AbstractWeaTableComponentSendResultMsg weaTableComponentSendResultMsg = new DefaultWeaTableComponentSendResultMsg();
        //创建 table 实体类
        AbstractWeaTable weaTable = new DefaultWeaTable();
        //设置查询字段
        weaTable.setBackfields("id,demo_input,demo_select,demo_browser,demo_datepicker,demo_timepicker");
        //设置from语句
        weaTable.setSqlform("weaverboot_pc_demo");
        //拼接where语句
        StringBuilder sqlWhereBuilder = new StringBuilder("1=1");
        if (BaseTools.notNullString(demoTable.getDemo_input())){
            sqlWhereBuilder.append(" AND demo_input = '").append(demoTable.getDemo_input()).append("'");
        }
        if (BaseTools.notNullString(demoTable.getDemo_select())){
            sqlWhereBuilder.append(" AND demo_select = '").append(demoTable.getDemo_select()).append("'");
        }
        if (BaseTools.notNullString(demoTable.getDemo_datepicker())){
            sqlWhereBuilder.append(" AND demo_datepicker = '").append(demoTable.getDemo_datepicker()).append("'");
        }
        if (BaseTools.notNullString(demoTable.getDemo_timepicker())){
            sqlWhereBuilder.append(" AND demo_timepicker = '").append(demoTable.getDemo_timepicker()).append("'");
        }
        weaTable.setSqlwhere(sqlWhereBuilder.toString());
        //设置orderby
        weaTable.setSqlorderby("id");
        //设置主键
        weaTable.setSqlprimarykey("id");
        //创建id字段
        AbstractWeaTableColumn idColumn = new DefaultWeaTableColumn("id");
        idColumn.setDisplay(WeaBooleanEnum.FALSE);
        //创建字段
        AbstractWeaTableColumn demoBrowserColumn = new DefaultWeaTableColumn("20%","人力资源浏览按钮","demo_browser","demo_browser","com.weaverboot.demoTable.service.demo03.impl.DemoServiceImpl03.transMethod");
        //创建字段
        AbstractWeaTableColumn demoInputColumn = new DefaultWeaTableColumn("20%","输入框","demo_input","demo_input");
        //创建字段
        AbstractWeaTableColumn demoSelectColumn = new DefaultWeaTableColumn("20%","选择框","demo_select","demo_select");
        //创建字段
        AbstractWeaTableColumn demoDatepickerColumn = new DefaultWeaTableColumn("20%","时间区间","demo_datepicker","demo_password");
        //创建字段
        AbstractWeaTableColumn demoTimepickerColumn = new DefaultWeaTableColumn("20%","时间选择","demo_timepicker","demo_password");
        //创建字段
        weaTable.addWeaTableColumn(demoBrowserColumn).addWeaTableColumn(demoInputColumn).addWeaTableColumn(demoSelectColumn).addWeaTableColumn(demoDatepickerColumn).addWeaTableColumn(demoTimepickerColumn);
        //将创建好的table 放入消息体并返回
        weaTableComponentSendResultMsg.setWeaTable(weaTable);

        WeaFormSendComponentResultMsg weaFormSendComponentResultMsg = new WeaFormSendComponentResultMsg();
        return weaTableComponentSendResultMsg;
    }
}
